package com.relytosoft.mizar.analyze.handle.service.impl;

import com.relytosoft.mizar.analyze.base.entity.algo.AYNonVehicle;
import com.relytosoft.mizar.analyze.base.entity.algo.AYPerson;
import com.relytosoft.mizar.analyze.base.entity.algo.AYVehicle;
import com.relytosoft.mizar.analyze.base.entity.pojo.dto.controlCondition.TextNonVehicleConditionDto;
import com.relytosoft.mizar.analyze.base.entity.pojo.dto.controlCondition.TextPeopleConditionDto;
import com.relytosoft.mizar.analyze.base.entity.pojo.dto.controlCondition.TextVehicleConditionDto;
import com.relytosoft.mizar.analyze.common.utils.StringUtil;
import com.relytosoft.mizar.analyze.handle.service.ControlTypeService;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;
import java.util.Objects;

/**
 * @author wss
 * @version 1.0
 * @date 2022/5/23 23:32
 */
@Service
public class ControlTypeServiceImpl implements ControlTypeService {

    @Override
    public Boolean textPeopleVerify(List<AYPerson> personList, TextPeopleConditionDto conditionDto) {
        Iterator<AYPerson> personIterator = personList.iterator();
        while (personIterator.hasNext()) {
            AYPerson ayPerson = personIterator.next();
            if (!StringUtil.conditionVerify(conditionDto.getAge(), ayPerson.getAge())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getGenderCode(), ayPerson.getGenderCode())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getCoatColor(), ayPerson.getCoatColor())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getCoatLength(), ayPerson.getCoatLength())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getCoatStyle(), ayPerson.getCoatStyle())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getTrousersColor(), ayPerson.getTrousersColor())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getTrousersStyle(), ayPerson.getTrousersStyle())) {
                return false;
            }
        }
        return true;
    }

    @Override
    public Boolean textVehicleVerify(List<AYVehicle> vehicleList, TextVehicleConditionDto conditionDto) {
        Iterator<AYVehicle> vehicleIterator = vehicleList.iterator();
        while (vehicleIterator.hasNext()) {
            AYVehicle ayVehicle = vehicleIterator.next();
            if (!StringUtil.conditionVerify(conditionDto.getPlateClass(), ayVehicle.getPlateClass())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getVehicleClass(), ayVehicle.getVehicleClass())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getVehicleColor(), ayVehicle.getVehicleColor())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getVehicleModel(), ayVehicle.getVehicleModel())) {
                return false;
            }
            if (!StringUtil.conditionVerify(conditionDto.getPlateNo(), ayVehicle.getPlateNo())) {
                return false;
            }
            if (!Objects.equals(conditionDto.getHasRack(), ayVehicle.getHasRack())) {
                return false;
            }
            if (!Objects.equals(conditionDto.getHasSpareTire(), ayVehicle.getHasSpareTire())) {
                return false;
            }
            if (!Objects.equals(conditionDto.getHasSunroof(), ayVehicle.getHasSunroof())) {
                return false;
            }
        }
        return true;
    }

    @Override
    public Boolean textNonVehicleVerify(List<AYNonVehicle> nonVehicleList, TextNonVehicleConditionDto conditionDto) {
        Iterator<AYNonVehicle> nonVehicleIterator = nonVehicleList.iterator();
        while (nonVehicleIterator.hasNext()) {
            AYNonVehicle ayNonVehicle = nonVehicleIterator.next();
            if (!StringUtil.conditionVerify(conditionDto.getVehicleClass(), ayNonVehicle.getVehicleClass())) {
                return false;
            }
        }
        return true;
    }

}
